﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var username = Login1.UserName.Trim();
            var password = Login1.Password.Trim();

            var sql = string.Format("select * from Users where username='{0}' and  password='{1}'", username, password);

            var dt = DbHelper.GetData(sql);
            if (dt.Rows.Count == 1)
            {
                var row = dt.Rows[0];
                var IsActived = (bool)row.ItemArray[3];
                var IsDeleted = (bool)row.ItemArray[4];
                if (IsDeleted)
                {
                    //已删除
                    Label1.Text = "当前账号已删除或注销，详情请联系客服！";
                }
                else
                {
                    if (IsActived)
                    {
                        //已启用
                        Session["UserName"] = username;
                        Response.Redirect("default.aspx");
                        
                        
                    }
                    else
                    {
                        //验证失败，请重试！！
                        Label1.Text = "账号出现异常";
                    }
                }
            }
            else
            {
                //验证失败，请重试！！
                Label1.Text = "//验证失败，请重试！！";
            }
        }
    }
}